﻿using System;
using System.Collections.Generic;
using System.Linq;
using Framework.Exceptions.RepositoryExceptions;
using Interfaces.Repositories;
using Interfaces.RepositoryModels.ExternalModels.FilterModels;

namespace SQLRepositories.FilterRepositories
{
    public class QuoteisFiltereRepository : EntityBaseRepository<QuoteisFilterModel>, IFilterRepository<QuoteisFilterModel>
     {
         public QuoteisFiltereRepository(IDBEconomicInformationServiceContext context) 
             : base(context)
         {}

         public void Create(QuoteisFilterModel item)
         {
             Context.QuoteisFilters.Add(item);
             Context.SaveChanges();
         }

         public QuoteisFilterModel GetById(Guid id)
         {
             return Context.QuoteisFilters.FirstOrDefault(x => x.Id.Equals(id));
         }

         public void Delete(Guid id)
         {
             var removedItem = Context.QuoteisFilters.FirstOrDefault(x => x.Id.Equals(id));
             if(removedItem == null)
                 throw new EntityNotFoundException("QuoteisFilter");
             Context.QuoteisFilters.Remove(removedItem);
             Context.SaveChanges();
         }

         public void Delete(QuoteisFilterModel item)
         {
             Context.QuoteisFilters.Remove(item);
             Context.SaveChanges();
         }

         public IEnumerable<QuoteisFilterModel> GetAll()
         {
             return Context.QuoteisFilters;
         }
     }
}
